package com.nineclock.attendance.controller;

import com.nineclock.api.attendance.AttendanceControllerApi;
import com.nineclock.attendance.dto.AttendGroupDTO;
import com.nineclock.attendance.service.AttendanceService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class AttendanceController implements AttendanceControllerApi {
    @Autowired
    AttendanceService attendanceService;
    /**
     * 获取
     *
     * @return
     */
    @GetMapping("/attendGroup")
    @Override
    public Result<PageResult<AttendGroupDTO>> getAttendGroupByUserId(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                                                     @RequestParam(value = "pageSize",defaultValue = "8")Integer pageSize) {
        PageResult<AttendGroupDTO> list = attendanceService.getAttendGroupByUserId(page, pageSize);
        return Result.success(list);
    }

    /**
     * 添加考勤组
     * @param attendGroupDTO
     * @return
     */
    @PostMapping("/attendGroup")
    @Override
    public Result attendGroup(@RequestBody AttendGroupDTO attendGroupDTO) {
        attendanceService.attendGroup(attendGroupDTO);
        return Result.success();
    }

    /**
     * 获取当前登录用户的考勤组
     *
     * @return
     */
    @GetMapping("/getAttendGroupByUserId")
    @Override
    public Result<AttendGroupDTO> queryAttendGroup() {
        AttendGroupDTO attendGroupDTO = attendanceService.queryAttendGroup();
        return Result.success(attendGroupDTO);
    }
}
